"use strict";

/**
 * @ngdoc function
 * @name jgappApp.controller:PersonnelCctipCtrl
 * @description
 * # PersonnelCctipCtrl
 * Controller of the jgappApp
 */
angular
  .module("jgappApp")
  .controller(
    "PersonnelCctipCtrl",
    function($scope, openApi, Util, $routeParams, FormSubmit) {
      var id = ($scope.process_id = $routeParams.id);
      $scope.unitList = [
        {
          key: "天",
          value: "天"
        },
        {
          key: "小时",
          value: "小时"
        }
      ];
      $scope.submit = function(operationId) {
        // 底部类型end
        var options = {};
        // 流程id
        options.id = id;
        // 根据operationId判断是草稿还是提交
        options.operationId = operationId;
        options.urlParam = openApi.travelApply;
        options.param = angular.copy($scope.param, {});
        FormSubmit.submit(options, $scope);
      };
      $scope.validate = function() {
        if (!$scope.param.startTravelDate) {
          Util.Toast("请选择出差起始日期");
          return;
        }
        if (!$scope.param.endTravelDate) {
          Util.Toast("请选择出差截至日期");
          return;
        }
        if (!$scope.param.days) {
          Util.Toast("请填写出差时长");
          return;
        }
        if (!Util.checkDays($scope.param.days)) {
          Util.Toast("出差时长要为0.5的倍数");
          return;
        }

        if (!$scope.param.travelCity) {
          Util.Toast("请填写出差城市");
          return;
        }
        if (!$scope.param.reason) {
          Util.Toast("请填写出差事由");
          return;
        }
        if (!$scope.validation.passvalidation) {
          Util.Toast($scope.validation.tip);
          return;
        }
        return true;
      };
      var init = function() {
        // 获取回显的详细信息
        Util.getDetailData(id, function(data) {
          $scope.param = data;
          $scope.param.unit = $scope.param.unit || $scope.unitList[0].value;
        });
      };
      // 初始化
      init();
    }
  );
